]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
extensionPrefs: Use imports.package.start()
authorFlorian Müllner <fmuellner@gnome.org>
Thu, 5 Mar 2020 16:44:27 +0000 (17:44 +0100)
committerFlorian Müllner <florian.muellner@gmail.com>
Thu, 19 Mar 2020 14:27:35 +0000 (14:27 +0000)
We want to make the extensions app code more self-contained to make it
easier to build separately, and ultimately make it available on flathub.

One complication we are facing is that it is currently all over the source
tree:
 - js/extensionPrefs for the main code
 - src for the launcher process
 - data for .desktop file and icons

Switching from a C launcher to the imports.package module allows us to
consolidate the first two, and will also take care of the annoying
setup bits (defining JS search path, extending GI lookup, loading
resources).

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1081

js/extensionPrefs/gnome-shell-extension-prefs.in [new file with mode: 0644]
js/extensionPrefs/main.js
js/extensionPrefs/meson.build [new file with mode: 0644]
js/extensionPrefs/org.gnome.Extensions.data.gresource.xml [new file with mode: 0644]
js/extensionPrefs/org.gnome.Extensions.in [new file with mode: 0644]
js/extensionPrefs/org.gnome.Extensions.src.gresource.xml [new file with mode: 0644]
js/meson.build
js/prefs-resources.gresource.xml [deleted file]
src/gnome-shell-extension-prefs.c [deleted file]
src/meson.build

diff --git a/js/extensionPrefs/gnome-shell-extension-prefs.in b/js/extensionPrefs/gnome-shell-extension-prefs.in
new file mode 100644 (file)
index 0000000..dc6d627
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+@gjs@ @pkgdatadir@/@app_id@ "$@"
index 02e68c76d651b0bb3b60f2635a54fa51cb6e7498..936598c0542b29fae393473cba1ec911bcac123d 100644 (file)
@@ -2,13 +2,13 @@
 imports.gi.versions.Gdk = '3.0';
 imports.gi.versions.Gtk = '3.0';
 
+imports.package.initFormat();
+
 const Gettext = imports.gettext;
 const { Gdk, GLib, Gio, GObject, Gtk } = imports.gi;
-const Format = imports.format;
 
 const _ = Gettext.gettext;
 
-const Config = imports.misc.config;
 const ExtensionUtils = imports.misc.extensionUtils;
 const { loadInterfaceXML } = imports.misc.fileUtils;
 
@@ -46,7 +46,7 @@ class Application extends Gtk.Application {
         super.vfunc_startup();
 
         let provider = new Gtk.CssProvider();
-        let uri = 'resource:///org/gnome/shell/css/application.css';
+        let uri = 'resource:///org/gnome/Extensions/css/application.css';
         try {
             provider.load_from_file(Gio.File.new_for_uri(uri));
         } catch (e) {
@@ -61,11 +61,9 @@ class Application extends Gtk.Application {
     }
 
     vfunc_command_line(commandLine) {
-        let args = commandLine.get_arguments();
-
-        if (args.length) {
-            let uuid = args[0];
+        let [prgName_, uuid] = commandLine.get_arguments();
 
+        if (uuid) {
             // Strip off "extension:///" prefix which fakes a URI, if it exists
             uuid = stripPrefix(uuid, 'extension:///');
 
@@ -79,7 +77,7 @@ class Application extends Gtk.Application {
 
 var ExtensionsWindow = GObject.registerClass({
     GTypeName: 'ExtensionsWindow',
-    Template: 'resource:///org/gnome/shell/ui/extensions-window.ui',
+    Template: 'resource:///org/gnome/Extensions/ui/extensions-window.ui',
     InternalChildren: [
         'userList',
         'systemList',
@@ -219,7 +217,7 @@ var ExtensionsWindow = GObject.registerClass({
             comments: _('Manage your GNOME Extensions'),
             license_type: Gtk.License.GPL_2_0,
             logo_icon_name: 'org.gnome.Extensions',
-            version: Config.PACKAGE_VERSION,
+            version: imports.package.version,
 
             transient_for: this,
             modal: true,
@@ -571,7 +569,7 @@ var Expander = GObject.registerClass({
 
 var ExtensionRow = GObject.registerClass({
     GTypeName: 'ExtensionRow',
-    Template: 'resource:///org/gnome/shell/ui/extension-row.ui',
+    Template: 'resource:///org/gnome/Extensions/ui/extension-row.ui',
     InternalChildren: [
         'nameLabel',
         'descriptionLabel',
@@ -751,8 +749,6 @@ function initEnvironment() {
 
         userdatadir: GLib.build_filenamev([GLib.get_user_data_dir(), 'gnome-shell']),
     };
-
-    String.prototype.format = Format.format;
 }
 
 function main(argv) {
diff --git a/js/extensionPrefs/meson.build b/js/extensionPrefs/meson.build
new file mode 100644 (file)
index 0000000..97da997
--- /dev/null
@@ -0,0 +1,46 @@
+app_id = 'org.gnome.Extensions'
+prgname = 'gnome-shell-extension-prefs'
+
+launcherconf = configuration_data()
+launcherconf.set('app_id', app_id)
+launcherconf.set('PACKAGE_NAME', meson.project_name())
+launcherconf.set('PACKAGE_VERSION', meson.project_version())
+launcherconf.set('prefix', prefix)
+launcherconf.set('libdir', libdir)
+launcherconf.set('pkgdatadir', pkgdatadir)
+launcherconf.set('gjs', gjs.path())
+
+configure_file(
+  input: prgname + '.in',
+  output: prgname,
+  configuration: launcherconf,
+  install_dir: bindir,
+  install_mode: 'rwxr-xr-x',
+)
+
+configure_file(
+  input: app_id + '.in',
+  output: app_id,
+  configuration: launcherconf,
+  install_dir: pkgdatadir,
+)
+
+config_dir = '@0@/..'.format(meson.current_build_dir())
+
+gnome.compile_resources(
+  app_id + '.src',
+  app_id + '.src.gresource.xml',
+  dependencies: [config_js],
+  source_dir: ['.', '..', config_dir],
+  gresource_bundle: true,
+  install: true,
+  install_dir: pkgdatadir
+)
+
+gnome.compile_resources(
+  app_id + '.data',
+  app_id + '.data.gresource.xml',
+  gresource_bundle: true,
+  install: true,
+  install_dir: pkgdatadir
+)
diff --git a/js/extensionPrefs/org.gnome.Extensions.data.gresource.xml b/js/extensionPrefs/org.gnome.Extensions.data.gresource.xml
new file mode 100644 (file)
index 0000000..f6fc66b
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/Extensions">
+    <file>css/application.css</file>
+
+    <file>ui/extension-row.ui</file>
+    <file>ui/extensions-window.ui</file>
+  </gresource>
+</gresources>
diff --git a/js/extensionPrefs/org.gnome.Extensions.in b/js/extensionPrefs/org.gnome.Extensions.in
new file mode 100644 (file)
index 0000000..da7ab25
--- /dev/null
@@ -0,0 +1,6 @@
+imports.package.start({
+    name: '@PACKAGE_NAME@',
+    version: '@PACKAGE_VERSION@',
+    prefix: '@prefix@',
+    libdir: '@libdir@',
+});
diff --git a/js/extensionPrefs/org.gnome.Extensions.src.gresource.xml b/js/extensionPrefs/org.gnome.Extensions.src.gresource.xml
new file mode 100644 (file)
index 0000000..9b0fa09
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/Extensions/js">
+    <file>main.js</file>
+
+    <file>misc/config.js</file>
+    <file>misc/extensionUtils.js</file>
+    <file>misc/fileUtils.js</file>
+  </gresource>
+</gresources>
index 9a230d65d7071a4ed55d28c3a5be28897ada195b..8b131d8ddab14b2869f05b69716478bf1f5144ee 100644 (file)
@@ -1,5 +1,6 @@
 subdir('misc')
 subdir('dbusServices')
+subdir('extensionPrefs')
 
 js_resources = gnome.compile_resources(
   'js-resources', 'js-resources.gresource.xml',
@@ -14,10 +15,3 @@ portal_resources = gnome.compile_resources(
   c_name: 'portal_js_resources',
   dependencies: [config_js]
 )
-
-prefs_resources = gnome.compile_resources(
-  'prefs-resources', 'prefs-resources.gresource.xml',
-  source_dir: ['.', meson.current_build_dir()],
-  c_name: 'prefs_js_resources',
-  dependencies: [config_js]
-)
diff --git a/js/prefs-resources.gresource.xml b/js/prefs-resources.gresource.xml
deleted file mode 100644 (file)
index 548a46a..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<gresources>
-  <gresource prefix="/org/gnome/shell">
-    <file>extensionPrefs/main.js</file>
-
-    <file>misc/config.js</file>
-    <file>misc/extensionUtils.js</file>
-    <file>misc/fileUtils.js</file>
-
-    <file alias="css/application.css">extensionPrefs/css/application.css</file>
-
-    <file alias="ui/extension-row.ui">extensionPrefs/ui/extension-row.ui</file>
-    <file alias="ui/extensions-window.ui">extensionPrefs/ui/extensions-window.ui</file>
-  </gresource>
-</gresources>
diff --git a/src/gnome-shell-extension-prefs.c b/src/gnome-shell-extension-prefs.c
deleted file mode 100644 (file)
index 7ff728e..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-#include "config.h"
-
-#include <gjs/gjs.h>
-#include <glib/gi18n.h>
-
-int
-main (int argc, char *argv[])
-{
-  const char *search_path[] = { "resource:///org/gnome/shell", NULL };
-  GError *error = NULL;
-  GjsContext *context;
-  int status;
-
-  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
-  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
-  textdomain (GETTEXT_PACKAGE);
-
-  context = g_object_new (GJS_TYPE_CONTEXT,
-                          "search-path", search_path,
-                          NULL);
-
-  if (!gjs_context_define_string_array(context, "ARGV",
-                                       argc - 1, (const char**)argv + 1,
-                                       &error))
-    {
-      g_message("Failed to defined ARGV: %s", error->message);
-      g_error_free (error);
-      g_object_unref (context);
-
-      return 1;
-    }
-
-  if (!gjs_context_eval (context,
-                         "const Main = imports.extensionPrefs.main; Main.main(ARGV);",
-                         -1,
-                         "<main>",
-                         &status,
-                         &error))
-    {
-      g_message ("Execution of main.js threw exception: %s", error->message);
-      g_error_free (error);
-      g_object_unref (context);
-
-      return status;
-    }
-
-  g_object_unref (context);
-  return 0;
-}
index 8e18e30805012c4359257d72a15e5a0af20da166..05bdb9beabab657201f9fe23b45dcf1f14c9bd88 100644 (file)
@@ -249,15 +249,6 @@ executable('gnome-shell', 'main.c',
   install: true
 )
 
-executable('gnome-shell-extension-prefs',
-  'gnome-shell-extension-prefs.c', prefs_resources,
-  c_args: tools_cflags,
-  dependencies: tools_deps,
-  include_directories: [conf_inc],
-  install: true
-)
-
-
 if have_networkmanager
   executable('gnome-shell-portal-helper',
     'gnome-shell-portal-helper.c', portal_resources,